package fmi.chesstern.game;

public final class BoardField {
	private int row;
	private int column;
	
	public BoardField(int row, int col) {
		this.row = row;
		this.column = col;
	}
	
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + column;
		result = prime * result + row;
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}
		if (obj == null || !(obj instanceof BoardField)) {
			return false;
		}
		BoardField other = (BoardField) obj;
		return column == other.column && row == other.row;
	}

	public static boolean isFieldCorrect(BoardField field) {
		boolean isCorrect = false;
		int row = field.getRow();
		int col = field.getColumn();
		if (row >= 0 && row <= 7 && col >= 0 && col <= 7)
			isCorrect = true;
		return isCorrect;
	}
	
	public int getRow() {
		return row;
	}

	public int getColumn() {
		return column;
	}
	
	public BoardField offsetBy(int deltax, int deltay) {
		return new BoardField(row + deltax, column + deltay);
	}
}
